import { createStore } from 'redux';

const initState = { count: 100, msg: '123', list: [{ id: 1, task: '学习React', isDone: true }] };

function countReducer(state = initState, { type, payload }) {
  console.log('action.payload  ----->  ', payload);
  switch (type) {
    case 'add':
      return { ...state, count: state.count + payload };
    case 'des':
      return { ...state, count: state.count - payload };
    default:
      return state;
  }
}

const store = createStore(countReducer);
export default store;

// 1. 定义一个函数，函数接收payload，返回一个action对象
export const addActionCreator = (payload) => {
  return {
    type: 'add',
    payload,
  };
};

export const desActionCreator = (payload) => {
  return {
    type: 'des',
    payload,
  };
};
